package cn.edu.hnu.gpg.util;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public class FileUtils {

    public static byte[] readFileToByteArray(File file) throws IOException {

        FileInputStream inputStream = new FileInputStream(file);
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream(inputStream.available());
        byte[] buffer = new byte[1024];

        while (inputStream.available() > 0) {
            int length = inputStream.read(buffer);
            outputStream.write(buffer, 0, length);
        }

        return outputStream.toByteArray();
    }
}
